package com.ymatou.userservice.testcase;

import java.util.Date;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.userservice.parameter.UserProfileRequestDtoBean;
import com.ymatou.userservice.service.UserProfileRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.model.YmtUsers;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 修改用户信息 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_UserProfileRequestDto {
	private static UserProfileRequestDtoBean upb;
	private static UserProfileRequestDtoCall upc;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改用户信息");
	}

	@Before
	public void caseUp() {
		upb = new UserProfileRequestDtoBean();
		upc = new UserProfileRequestDtoCall();

	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(upc.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserProfileRequestDto_001() {
		Logger.start(true,"修改用户信息成功");
		try {
			Map user = UserCallService.registerUser(TestDataManager.getEmail(), null,null);
			int userId = (Integer)user.get("userId");
			Date oldtime = new YmtUsersWapper().getYmtUsers(userId).getLastupdatetime();
			String sPhone = TestDataManager.getPhoneNum();
			upb.setISex(0);
			upb.setIUserId(userId);
			upb.setSIdCard("000000000000000000");
			upb.setSPhone(sPhone);
			upb.setSUserLogoUrl("http://p5.img.ymatou.com/upload/userlogo/original/422750_32a28b7fbc0c457f87f5501c6e7d84a8_o.jpg");
			upc.setData(upb);
			upc.callService();
			Logger.verifyEquals(ECode.SUCCESS, upc.getResponseCode(), "验证Code");
			Logger.verifyEquals(true, upc.getSuccess(), "验证Success");
			YmtUsers users = new YmtUsersWapper().getYmtUsers(Integer.valueOf(userId));
			Logger.verifyEquals("000000000000000000", users.getSidcardno(), "验证Sidcardno");
			Logger.verifyEquals(sPhone, users.getSphone(), "验证sPhone");
			Logger.verifyEquals(0, users.getIsex(), "验证Isex");
			Logger.verifyEquals(
					"http://p5.img.ymatou.com/upload/userlogo/original/422750_32a28b7fbc0c457f87f5501c6e7d84a8_o.jpg",
					users.getSuserlogourl(), "验证Suserlogourl");
			Logger.verifyEquals(true, users.getLastupdatetime().after(oldtime),
					"验证Lastupdatetime更新:" + users.getLastupdatetime());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UserProfileRequestDto_002() {
		Logger.start(false,"输入错误userid修改用户信息失败");
		try {
			upb.setISex(0);
			upb.setIUserId(-8);
			upb.setSIdCard("000000000000000000");
			upb.setSPhone(TestDataManager.getPhoneNum());
			upb.setSUserLogoUrl("http://p5.img.ymatou.com/upload/userlogo/original/422750_32a28b7fbc0c457f87f5501c6e7d84a8_o.jpg");
			upc.setData(upb);
			upc.callService();
			Logger.verifyEquals(ECode.ERROR400, upc.getResponseCode(), "验证Code");
			Logger.verifyEquals(false, upc.getSuccess(), "验证Success");
			Logger.verifyEquals("false", upc.getString("Result"), "验证Result");
			Logger.verifyEquals("UserIdError", upc.getString("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UserProfileRequestDto_003() {
		Logger.start(false,"输入错误userid修改用户信息失败");
		try {
			upb.setISex(0);
			upb.setIUserId(Integer.MAX_VALUE);
			upb.setSIdCard("000000000000000000");
			upb.setSPhone(TestDataManager.getPhoneNum());
			upb.setSUserLogoUrl("http://p5.img.ymatou.com/upload/userlogo/original/422750_32a28b7fbc0c457f87f5501c6e7d84a8_o.jpg");
			upc.setData(upb);
			upc.callService();
			Logger.verifyEquals(ECode.ERROR400, upc.getResponseCode(), "验证Code");
			Logger.verifyEquals(false, upc.getSuccess(), "验证Success");
			Logger.verifyEquals("false", upc.getString("Result"), "验证Result");
			Logger.verifyEquals("用户不存在", upc.getString("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}